package com;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * Created by cuich on 2018/1/5.
 */
@RestController
public class ProvideController {
    @Autowired
    private DiscoveryClient client;

    @Value("${spring.application.name}")
    private String application;


    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public Object sayHello() {

        List<ServiceInstance> instances = client.getInstances(application);


        System.err.println(instances.get(0).getClass());


        User user = new User(1, "崔超");

        System.err.println(application);
       /* if(true)
        throw new RuntimeException();*/
        //return "instanceId:"+application+" send : Hello   World";
        return user;
    }

}
